package edu.njust.controller;

import edu.njust.pojo.Computer;
import edu.njust.pojo.ComputerRoom;
import edu.njust.service.ComputerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ComputerController")
public class ComputerController {

    @Autowired
    @Qualifier("ComputerServiceImpl")
    private ComputerService computerService;

    //—————————————管理员—————————————
    //显示所有机房
    @RequestMapping("/showAllComputerRoom")
    public List<ComputerRoom> allRoomList(){
        List<ComputerRoom> computerRoomList = computerService.getAllComputerRoom();
        return computerRoomList;
    }

    //显示某个机房的所有电脑
    @RequestMapping("/showAllComputer")
    public List<Computer> allComputerList(@RequestParam("room_id") String room_id){
        List<Computer> computerList = computerService.getAllComputer(room_id);
        return computerList;
    }

    //修改电脑状态
    @RequestMapping("/changeState")
    public void updateComputerState(@RequestBody List<Computer> computerList){
        for (Computer computer : computerList){
            if (computer.isUsable() == true)
                computerService.modifyComputerState(computer.getRoom_id(), computer.getId(), false);
            else if (computer.isUsable() == false)
                computerService.modifyComputerState(computer.getRoom_id(), computer.getId(), true);
        }
    }

}
